//科室管理的全局变量
var gongyingshangxx = {
	url: {
	   gongyingshanglbURL: function () {
			return '/gongyingshang/getGongyingslist';
		},
		gongyingshangcountURL: function () {
			return '/gongyingshang/getGongyingsCount';
		},qyjyGongyingshangURL:function(){
			return '/gongyingshang/jingyonggys';
		}
	},
	getListParams: function () {
		var gongyingmc = $.trim($('#gongyingmc').val());
		var zhuangtai1 = $('#zhuangtaidiv').text();
		var jinyongbz;
		switch(zhuangtai1){
		case('启用'): jinyongbz = 0;
		break;
		case('禁用'): jinyongbz = 1;
		};
		var jinyongbz = $('#zhuangtai').val();
		var params = {
			"mingcheng": gongyingmc,
			"jinyongbz": jinyongbz
		}
		return params;
	},
	init: function(){
		gongyingshangxx.bandFunction();
		gongyingshangxx.fenye();
	},
	getinsertMsg: function(){
		
	},
	getmsg: function(){
		
	},
	find: function(){
		
	},
	//绑定的方法
	bandFunction: function(){
		// 二级导航
		var A = 0;
		$(".nav-clinic-info").click(function(){	
			if(A>0){
				//confirm("编辑内容没有保存，是否离开？");
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
		})
		// 科室管理
		$(".nav-keshi").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
		})
		$(".nav-staff-info").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
		})
		$(".nav-prescription-template").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
		})
		$(".advice-template").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
		})
		$(".test-items").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
				
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
		})
		$(".addition-free").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
		})
		//病种目录
		$(".bingzhongml").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        window.location.href = "zhensuoxx.jsp?navMingChen="+$(this).text();
		})
		$(".gongyingshang").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".s-m-nav .g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
					$("#cedan").html();
					window.location.href = "gongyingshang.jsp";
					return false;
				}else{
					return false;
				};
			};
			$(".s-m-nav .g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
	        $("#cedan").html();
	        window.location.href = "gongyingshang/gongyingshang.jsp";
		});
		
		//回车事件绑定到查询按钮
		$(document).keydown(function(){ 
			if(event.keyCode==13){ 
			$("#gongys-search").trigger('click'); 
			return false;
			}
		});
		
		// 新建页面跳转
		$(document).on('click','#gongys-new',function(){
			window.location.href = path+"gongyingshang-new.jsp";
		});
		
		// 状态下拉
		$('#ghzhuangtaiul li').on('click', function () {
			$('#zhuangtai').val($(this).attr('value'));
			$('#zhuangtaidiv').text($(this).text());
			$(this).parent().css('display', 'none');
			gongyingshangxx.fenye();
		});
		// 详情事件
		$(document).on('click', '.caozuo1', function () {
			var gingyingshangid = $(this).parent().attr('id');
			window.location.href = 'gongyingshang-detail.jsp?gingyingshangid=' + gingyingshangid;
		});
		// 查询按钮点击
		$('#gongys-search').on('click', function () {
			gongyingshangxx.fenye();
		});
		
		// 重置按钮
		$('#gongys-reset').on('click', function () {
			$('#gongyingmc').val('');
			$('#ghzhuangtaiul').children('li:eq(0)').trigger('click');
			gongyingshangxx.fenye();
		});
		// 禁用/启用操作
		$(document).on("click", "table .caozuo2", function(){
			var gingyingshangid = $(this).parent().attr('id');
			if($(this).text() == "禁用"){
				$('#qiyongtext').text("当前供应商是否禁用");
				$('#jyqy-modal #queding').text("禁用");
				$('#jyqybz').val(1);
			}else{
				$('#qiyongtext').text("当前供应商是否启用");
				$('#jyqy-modal #queding').text("启用");
				$('#jyqybz').val(0);
			}
			$("#jyqy-modal").modal();
			$('#jyqy-modal #queding').val(gingyingshangid);
		});
		//点击确定
		$(document).on("click", "#jyqy-modal #queding", function(){
			var bzval=$('#jyqybz').val();
			gongyingshangxx.qyjyGongyingshang($(this).val(),bzval);
			$('#jyqy-modal').modal('hide');
		})
	},
	fenye: function() {// 分页
		fenye.fenye(gongyingshangxx.url.gongyingshangcountURL(), gongyingshangxx.url.gongyingshanglbURL(),
			gongyingshangxx.getListParams(), "pagination-gongyingshang", "gongyingstb");
	},xinjian:function(){//新建
		
	},getZdGongyingshang(){//检索字典供应商
		
	},convertZhuangtaiToCaozuo: function(value) {// 状态前后端转换
		var result = "";
		switch (value) {
			case 0:
				result = "禁用";
				break;
			case 1:
				result = "启用";
				break;
		}
		return result;
	},qyjyGongyingshang: function(id,val){
		$.post(gongyingshangxx.url.qyjyGongyingshangURL(),{"id":id,"jinyongbz":val},function(result){
			if(result.succsess == true){
				if(result.data=="success"){
					gongyingshangxx.fenye();
				}else{
					notifyWarning(result.data);
				}
			}else{
				var result = "";
				if(val==0){
					result = "启用";
				}else{
					result = "禁用";
				}
				notifyWarning(result+"失败");
			}
		})
	}
}